package com.qyhl.module_home.utils.aboutrecyclerview;

import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qyhl.module_home.R;

import java.util.List;


/**
 * Created by android1 on 2017/12/11.
 */

public class HistortyAdapter extends RecyclerView.Adapter<HistortyAdapter.ViewHolder> {
    private List<String> list;
    private OnItemViewClickListener clickListener;

    public HistortyAdapter(List<String> list) {
        this.list = list;
    }

    public void remove(int position) {
        list.remove(position);
        notifyItemRemoved(position);
    }

    public void setOnItemClickListener(OnItemViewClickListener clickListener) {
        this.clickListener = clickListener;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private TextView search_history_item_text;
        private View layout;

        public ViewHolder(View itemView) {
            super(itemView);
            search_history_item_text = (TextView) itemView.findViewById(R.id.search_history_item_text);
            layout = itemView;
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.home_search_history_item, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        holder.search_history_item_text.setText(list.get(position));
        holder.layout.setOnClickListener(view -> clickListener.ClickListener(position));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

   public interface OnItemViewClickListener {
        void ClickListener(int position);
    }
}
